<template>
  <div class="side">
    <!-- 注册 -->
    <div class="regster">
      <el-row>
        <el-button type="primary" class="dakai" @click="createData()">提交</el-button>
      </el-row>
    </div>
    <div style="width:100%">
      <el-form :model="UserRegisterSet" label-position="right" label-width="177px" ref="dataForm">
        <el-form-item label="用户注册模式">
          <el-radio-group v-model="UserRegisterSet.userRegisterMode">
            <el-radio label="1">邮箱注册</el-radio>
            <el-radio label="2">手机注册</el-radio>
            <el-radio label="3">邮箱或手机注册</el-radio>
            <el-radio label="4">关闭</el-radio>
          </el-radio-group>
          <p style="margin:0;color:#606266">提示：关闭支付功能将导致网校用户无法购买商品。</p>
        </el-form-item>
        <div v-show="UserRegisterSet.userRegisterMode%2">
          <el-form-item label="邮箱验证登录">
            <el-radio-group v-model="UserRegisterSet.mailLoginValidate">
              <el-radio label="1">开启</el-radio>
              <el-radio label="2">关闭</el-radio>
            </el-radio-group>
            <p style="margin:0;color:#606266">开启后,邮箱未验证的用户将无法登录,请先保证邮件服务器已设置</p>
          </el-form-item>
          <el-form-item label="新用户激活邮件标题">
            <el-input v-model="UserRegisterSet.mailTitle" style="width:600px;color:#606266"></el-input>
          </el-form-item>
          <el-form-item label="新用户激活邮件内容">
            <el-input
              type="textarea"
              :rows="3"
              style="width:600px;"
              v-model="UserRegisterSet.mailContent">
            </el-input>
            <p style="margin:0;color:#606266;width:530px;">
              变量说明：
              {{nickName}} 为接收方用户昵称
              {{siteName}} 为网站名称
              {{siteUrl}} 为网站的地址
              {{verifyUrl}} 为邮箱验证地址
            </p>
          </el-form-item>
        </div>

        <el-form-item label="注册防护机制">
          <el-radio-group v-model="UserRegisterSet.registerSafe">
            <el-radio label="0">无</el-radio>
            <el-radio label="1">低</el-radio>
            <el-radio label="2">中</el-radio>
            <el-radio label="3">高</el-radio>
          </el-radio-group>
          <p style="margin:0;color:#606266">开启后,邮箱未验证的用户将无法登录,请先保证邮件服务器已设置</p>
        </el-form-item>
        <!-- 低 -->
        <div v-if="UserRegisterSet.registerSafe === 1">
          <el-form-item label="">
            <div class="doot">
              <div>方案说明</div>
              <div>邮箱注册时须要完成安全验证</div>
              <div>手机注册首次获取短信验证码时无安全验证</div>
              <div>60分钟内，同一IP地址第二次获取短信验证码时，须要完成安全验证</div>
            </div>
          </el-form-item>
        </div>

        <!-- 中 -->
        <div v-if="UserRegisterSet.registerSafe === 2">
          <el-form-item label="">
            <div class="doot">
              <div>方案说明</div>
              <div>邮箱注册时须要完成安全验证。</div>
              <div>手机注册首次获取短信验证码时无安全验证。</div>
              <div>60分钟内，同一IP地址第二次获取短信验证码时，须要完成安全验证</div>
              <div>同一IP24小时內只能注册30次。</div>
            </div>
          </el-form-item>
        </div>
        <!-- 高 -->
        <div v-if="UserRegisterSet.registerSafe === 3">
          <el-form-item label="">
            <div class="doot">
              <div>方案说明</div>
              <div>邮箱注册时须要完成安全验证。</div>
              <div>手机注册获取短信验证码时须要完成安全验证。</div>
              <div>同一IP24小时內只能注册10次。</div>
              <div>同一IP1小时內只能注册1个帐号。</div>
            </div>
          </el-form-item>
        </div>
        <div class="money">欢迎信息设置</div>
        <el-form-item label=" 发送欢迎信息">
          <el-radio-group v-model="UserRegisterSet.sendWelcome">
            <el-radio label="1">开启</el-radio>
            <el-radio label="2">关闭</el-radio>
          </el-radio-group>
          <p style="margin:0;color:#606266">欢迎信以站内私信的方式，发送给新用户。</p>
        </el-form-item>
        <el-form-item label="欢迎信息发送方">
          <el-input v-model="UserRegisterSet.sender" style="width:600px;color:#606266"></el-input>
          <p style="margin:0;color:#606266">通常为这个网站的管理员，请输入用户用户名。</p>
        </el-form-item>
        <el-form-item label="欢迎信息标题">
          <el-input v-model="UserRegisterSet.welcomeTitle" style="width:600px;color:#606266"></el-input>
        </el-form-item>
        <el-form-item label="欢迎信息内容">
          <el-input
            type="textarea"
            :rows="3"
            style="width:600px;"
            v-model="UserRegisterSet.welcomeContent">
          </el-input>
          <p style="margin:0;color:#606266;width:530px;">
            注意： 私信长度不能超过1000个字符。
            变量说明：
            {{nickName}} 为接收方用户用户名
            {{siteName}} 为网站名称
            {{siteUrl}} 为网站的地址
          </p>
        </el-form-item>
        <div class="weixin">服务条款数据</div>
        <el-form-item label="是否开启服务条款">
          <el-radio-group v-model="UserRegisterSet.openService">
            <el-radio label="1">开启</el-radio>
            <el-radio label="2">关闭</el-radio>
          </el-radio-group>
          <p style="margin:0;color:#606266">提示：关闭支付功能将导致网校用户无法购买商品。</p>
        </el-form-item>
        <el-form-item label="条款内容">
          <Tinymce v-model="UserRegisterSet.serviceContent" :height="200" style="width:500px;"/>
        </el-form-item>
      </el-form>
    </div>
  </div>

</template>

<script>
  import Tinymce from "@/components/Tinymce";
  import {addUserRegisterSet, getUserRegisterSet} from '@/api/system/userregister_set';
  import {getTenantId} from '@/utils/auth';

  export default {
    components: {
      Tinymce
    },
    data() {
      return {
        nickName: '',
        siteName: '',
        siteUrl: '',
        verifyUrl: '',
        UserRegisterSet: {
          userRegisterMode: '',
          mailLoginValidate: '',
          mailTitle: '',
          mailContent: '',
          registerSafe: '',
          sendWelcome: '',
          sender: '',
          welcomeTitle: '',
          welcomeContent: '',
          openService: '',
          serviceContent: ''
        }
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        getUserRegisterSet(getTenantId()).then(response => {
          this.UserRegisterSet = response.data
        }).catch(err => {
          console.log(err)
        })
      },
      createData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.UserRegisterSet.tenantId = getTenantId();
            addUserRegisterSet(this.UserRegisterSet).then(() => {
              this.$notify({
                title: '成功',
                message: '创建成功',
                type: 'success',
                duration: 2000
              });
              this.fetchData();
            })
          }
        })
      }
    }
  }
</script>

<style>
  .regster {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #e7e9ed;
    padding-top: 15px;
    padding-right: 34px;
  }

  .dakai {
    float: right;
    position: absolute;
    right: 10px;
    bottom: -25px;
  }

  .doot {
    width: 600px;
    margin-top: -14px;
    padding: 15px 15px;
    border-radius: 5px;
    background-color: #d9edf7;
    color: #326f8f;
    border-left: 5px solid #50bfff;
  }

  .money {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #ebf4ff;
    padding-right: 34px;
  }

  .weixin {
    width: 100%;
    height: 44px;
    line-height: 44px;
    margin-left: 15px;
    padding-left: 10px;
    background-color: #e4fafd;
    padding-right: 34px;
  }

</style>
